/*
 * Clear Re-Fill jQuery Plugin v0.1
 * http://code.google.com/p/jquery-clear-refill/
 *   by Francesco Terenzani (www.terenzani.it)
 * 
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 */

(function($){

$.fn.clearReFill = function() {
    
    this.each(function(){
        var $this = $(this);

        if ($this.is('input'))
            setEvents($this, 'val', $this.val());
            
        else if ($this.is('textarea'))
            setEvents($this, 'html', $this.html());
            
        else 
            return;

    });

    return this;
    
};

function setEvents($element, valueFunc, initValue) {

    $element
        .focus(function() {
            if ($element[valueFunc]() === initValue)
                $element[valueFunc]('');

        })
        .blur(function() {
            if ($element[valueFunc]() === '')
                $element[valueFunc](initValue);

        });
}

})(jQuery);
